#include "SDL.h"

#include "frame_rate_handler.hpp"

frame_rate_handler::frame_rate_handler(int fps)
  : fps_(fps)
{
	wait_until_ = SDL_GetTicks() + 1000/fps_;
}

void frame_rate_handler::next_frame()
{
	const int now = SDL_GetTicks();
	if(wait_until_ > now) {
		SDL_Delay(wait_until_ - now);
		wait_until_ += 1000/fps_;
	} else {
		wait_until_ = now + 1000/fps_;
	}
}
